﻿using MediatR;
using T.Vehicleservice.API.Application.Command.MainCommand;
using T.Vehicleservice.API.Application.Command.MaintenanceRecordCommand;
using T.Vehicleservice.Repository.ImpI;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.API.Application.CommandHandlers.MainCommandHandler
{
    public class MainDeleteCommandHandler : IRequestHandler<MainDeleteCommand, int>
    {
        protected readonly IMainIRepository mainIRepository;

        public MainDeleteCommandHandler(IMainIRepository mainIRepository)
        {
            this.mainIRepository = mainIRepository;
        }

        public async Task<int> Handle(MainDeleteCommand request, CancellationToken cancellationToken)
        {
            var MainIds = request.MaintenanceId;
            foreach (var item in MainIds)
            {
                var DelAll = mainIRepository.GetModelAsync(item).Result;
                DelAll.IsDeleted = true;
                DelAll.DeletedBy=request.DeletedBy;

                DelAll.DeletedDate = request.DeletedDate;
                   await mainIRepository.UpdateAsync(DelAll);
            }
            return 1;
        }
    }
}
